package com.module.circle.ui.dialog

import android.widget.ImageView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.common.app.data.bean.circle.CirclesMedalModel
import com.common.base.app.extras.load
import com.common.base.app.extras.yes
import com.module.circle.R

/**
 *
 * 作者：sosou
 *
 * 版本：1.0
 *
 * 创建日期：2025/08/12
 *
 * 描述：
 *
 * 修订历史：
 *
 */
class MedalInfoListAdapter(private val showProgress: Boolean = false) : BaseQuickAdapter<CirclesMedalModel, BaseViewHolder>(R.layout.circle_item_medal_grid_layout) {

    override fun convert(holder: BaseViewHolder, item: CirclesMedalModel) {

        holder.apply {
            itemView.rootView.alpha = 0.5f
            getView<ImageView>(R.id.picImg).load(item.getSortedBadgesByLevel()?.get(0)?.active_url, 0f)
            setText(R.id.tvName, item.getSortedBadgesByLevel()?.get(0)?.name)
            setText(R.id.tvDes, "${item.progress}/${item.getSortedBadgesByLevel()?.get(0)?.require}${item.unit}")
            setGone(R.id.tvDes, !showProgress)

            item.badges?.forEach {
                (item.current_level == it.level).yes {
                    getView<ImageView>(R.id.picImg).load(it.active_url, 0f)
                    setText(R.id.tvName, it.name)

                    itemView.rootView.alpha = 1f
                }
            }

            item.badges?.forEach {
                ((item.current_level+1) == it.level).yes {
                    setText(R.id.tvDes, "${item.progress}/${it.require}${item.unit}")
                }
            }
        }
    }
}